{% from 'include/input_macros.html' import copy_to_clipboard %}
{% extends "base.html" %}
{% block title %}{{ lang.menu_links.history.title }} {{ lang.words[service] }}{% endblock %}
{% block h2 %}{{ lang.menu_links.history.title }} {{ lang.words[service] }}{% endblock %}
{% block content %}
{% if user_subscription['user_status'] == 0 or user_subscription['user_plan'] == 'user' %}
	{% include 'include/no_sub.html' %}
{% else %}
<link href="{{ url_for('static', filename='css/table-6.3.9.css') }}" rel="stylesheet" type="text/css">
<link href="/inc/dataTables/buttons.dataTables.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" charset="utf8" src="/inc/dataTables.min.js"></script>
<script type="text/javascript" charset="utf8" src="/inc/dataTables/dataTables.buttons.min.js"></script>
<script type="text/javascript" charset="utf8" src="/inc/dataTables/jszip.min.js"></script>
<script type="text/javascript" charset="utf8" src="/inc/dataTables/pdfmake.min.js"></script>
<script type="text/javascript" charset="utf8" src="/inc/dataTables/vfs_fonts.js"></script>
<script type="text/javascript" charset="utf8" src="/inc/dataTables/buttons.html5.min.js"></script>
<script>
    $(document).ready(function() {
        $('#table_history').on('page.dt')
            .DataTable( {
                dom: 'Blfrtip',
                colReorder: true,
                "pageLength": 25,
                "order": [ 5, "desc" ],
                stateSave: true,
                "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                "columnDefs": [
                    {
                        "searchable": false,
                        "orderable": false
                    }
                ],
                buttons: [
                    'excelHtml5',
                    'csvHtml5',
                    'pdfHtml5'
                ],
            } );
    } );
</script>
<table class="overview hover order-column display compact" id="table_history">
    <thead>
        <tr class="overviewHead">
            <th class="padding10 first-collumn" style="width: 100px;">{{lang.words.service|title()}}</th>
            <th>{{lang.words.user|title()}}</th>
            <th style="width: 100px">{{lang.words.service|title()}} IP</th>
            <th style="width: 100px">{%if service == 'cluster' %}{{lang.words.cluster|title()}} {%else%}{{lang.words.server|title()}}{% endif %}</th>
            <th>{{lang.words.action|title()}}</th>
            <th>{{lang.words.date|title()}}</th>
            <th>{{lang.words.time|title()}}</th>
        </tr>
    </thead>
    <tbody>
    {% for h in history %}
    <tr>
        <td>{% if h.service is not none %} {{h.service[0].upper()}}{{h.service[1:]}}{% endif %}</td>
        <td>
            {% for u in users %}
            {% if u.user_id == h.user_id %}
            <a href="/app/history/user/{{u.user_id}}" title="Open history for {{u.username}}">{{ u.username }}</a>
            {% endif %}
            {% endfor %}
        </td>
        <td>{{ copy_to_clipboard(id=h.ip, value=h.ip) }}</td>
        <td>
            {% if h.server_ip != None %}
                {% if h.service in ('haproxy', 'nginx', 'apache', 'keepalived') %}
                    <a href="/app/service/{{h.service}}/{{h.server_ip}}" title="Open history for {{h.hostname}}">{{ h.hostname }}</a>
                {% elif h.service == 'HA cluster' %}
                    {{h.hostname}}
                {% endif %}
            {% endif %}
        </td>
        <td>{{h.action}}</td>
        <td>{{h.date|strftime('%Y %m %d')}}</td>
        <td>{{h.date|strftime('%H:%M:%S')}}</td>
    </tr>
    {% endfor %}
    </tbody>
</table>
{% endif %}
{% endblock %}
